
export  const onRestTableCellWidth = (columns) => {
    let ratio = 1
    let newWidth = window.innerWidth
    if(newWidth < 1920) {
        ratio = 1
    }else if(newWidth >= 1920 &&  newWidth < 2560) {
        ratio = 2
    }else if(newWidth>=2560 && newWidth <= 3440) {
        ratio = 2.4
    }else {
        ratio = 3
    }
    return  columns.map(item => {
       let t = {...item}
       if(t.width)
            t.width =  t.width* ratio
        if(t.minWidth) {
            t.minWidth =  t.minWidth * ratio
        }
        if(t.maxWidth) {
            t.maxWidth =  t.maxWidth * ratio
        }
        return t
    })
}

export  const onRestTreeTableCellWidth = (columns) => {
    let ratio = 1
    let newWidth = window.innerWidth
    if(newWidth < 1920) {
        ratio = 1
    }else if(newWidth >= 1920 &&  newWidth < 2560) {
        ratio = 2
    }else if(newWidth>=2560 && newWidth <= 3440) {
        ratio = 2.4
    }else {
        ratio = 3
    }
    function getTreeItem(node) {
      if (!node) return null;
      if(! Array.isArray(node)) {
        if(node.width) 
            node.width =  node.width * ratio
        if(node.minWidth) 
            node.minWidth =  node.minWidth * ratio
        return node
      }
      return  node.map(n => {
        if(n.width) 
            n.width =  n.width * ratio
        if(n.minWidth) 
             n.minWidth =  n.minWidth * ratio
        if (n.children ) {
            n.children = n.children.map(childNode => getTreeItem(childNode));
        }
      })
    }

    return getTreeItem(columns)
}


export  const onRestsearchLabelWidth = (labelWidth) => {
    let ratio = 1
    let newWidth = window.innerWidth
    if(newWidth < 1920) {
        ratio = 1
    }else if(newWidth >= 1920 &&  newWidth <= 2200) {
        ratio = 1
    }else if(newWidth > 2200 &&  newWidth <= 2560) {
        ratio = 1.2
    }else if(newWidth>2560 && newWidth <= 3440) {
        ratio = 2
    }else {
        ratio = 3
    }
    return  labelWidth*ratio
}
